{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a9792bb3",
   "metadata": {},
   "source": [
    "***  \n",
    "* 2022/09/20 week05  \n",
    "* 课堂笔记  \n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17fd15b4",
   "metadata": {},
   "source": [
    "# 本周内容  \n",
    "> 1.有序的数据结构之列表  \n",
    "> 2.用户输入  \n",
    "> 3.关于格式化文本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "72938a8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 内容引入\n",
    "\n",
    "网三_01_name = \"marry\"\n",
    "\n",
    "# 如何一个变量存放一个班的名字？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "5295322c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marry,alex,cola\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"marry,alex,cola\" # 一个变量存放一个班的名字\n",
    "print(网三_name_list)\n",
    "\n",
    "# 数据处理会不会很麻烦？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "53eb589c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'alex'"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取某个人名字时\n",
    "\n",
    "网三_name_list[6:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "401d7a67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考3：我想知道这个名单有多少个人名？\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d3be2f9",
   "metadata": {},
   "source": [
    "## 1.列表概念（仅ptpython有）\n",
    "> list可以放数值和字符，但一般要么一起放字符，要么一起放数值  \n",
    "  \n",
    "  \n",
    "> 一些有序数据结构通用的方法  \n",
    ">> 1.取值：通过索引值取出对应的内容  \n",
    ">> 2.切片：通过索引值区间取出对应的内容  \n",
    ">> 3.in可查看成员是否存在  \n",
    "  \n",
    "> 列表的一些方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4245b05",
   "metadata": {},
   "source": [
    "* 列表的数据本身不做修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4befff2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5160a075",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "b = [1]\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bd2dde4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = 5\n",
    "type(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3c5cc6a",
   "metadata": {},
   "source": [
    "### 1.1 列表的运算法则（Operation）\n",
    "* 列表的数据本身不做修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c18b891d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['marry', 'alex', 'cola'] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = [\"marry\",\"alex\",\"cola\"]\n",
    "print(网三_name_list,type(网三_name_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a7b85bc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'marry'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出 第一位同学的名字  \n",
    "网三_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0ab6bce4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看 有多少位同学\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c8be11d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三 marry\n",
      "网三 alex\n",
      "网三 cola\n"
     ]
    }
   ],
   "source": [
    "for i in 网三_name_list:\n",
    "    print(\"网三\",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "db9b922a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# in 查看数据是否存在\n",
    "\"cola\"in 网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "80db14c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关于运算法则（in + 切片 取值 len(s) s.count）\n",
    "网三_name_list_new = [\"xioaa\",\"xiaob\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "5edca238",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'alex', 'cola', 'xioaa', 'xiaob']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list + 网三_name_list_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "9a3d0d23",
   "metadata": {},
   "outputs": [],
   "source": [
    "# list中可以有重复值\n",
    "c = [\"A\",\"A\",\"B\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "57f7a68c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['A', 'A', 'B']"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9883423a",
   "metadata": {},
   "source": [
    "### 2.2列表的方法（Function）--对列表数据进行操作  \n",
    "> 1.增  \n",
    "> 2.删  \n",
    "> 3.改  \n",
    "> 4.查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d8c020fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list = [\"marry\",\"alex\",\"cola\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be53f449",
   "metadata": {},
   "source": [
    "#### append增加，增加元素到末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "29be47de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'alex', 'cola']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "4c1b03f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# append增加 运行一次增加一个值\n",
    "网三_name_list.append(\"jie\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "b5cc3fad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'alex', 'cola', 'jie']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20a9c39d",
   "metadata": {},
   "source": [
    "#### insert 增加元素到某个位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "96970e67",
   "metadata": {},
   "outputs": [],
   "source": [
    "# insert 增加元素到某个位置\n",
    "网三_name_list.insert(1,\"kai\") #放到索引值为1的内容之前，既取代1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "357951b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'kai', 'alex', 'cola', 'jie']"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4bcda47",
   "metadata": {},
   "source": [
    "#### remove删除 有相同内容时，删除第一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "3d8589a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove删除 有相同内容时，删除第一个\n",
    "网三_name_list.remove(\"kai\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "792e9500",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'alex', 'cola', 'jie']"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "7ed38bde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'marry,alex,cola'"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# remove 经常和 in 一起使用，先检查成员是否存在然后在remove\n",
    "\n",
    "if \"kai\" in 网三_name_list:\n",
    "    网三_name_list.remove(\"kai\")\n",
    "网三_name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e557d3c",
   "metadata": {},
   "source": [
    "#### pop 默认删除最后一个元素,给值可删除指定元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "4ef9d3a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'jie'"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pop 默认删除最后一个元素\n",
    "网三_name_list.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e8f140a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'alex', 'cola']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "686423fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'alex'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 给值可删除指定元素\n",
    "网三_name_list.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "f88f120f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['marry', 'cola']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5cb75fec",
   "metadata": {},
   "source": [
    "* 实践：移除19的元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "f9188538",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：移除19的元素\n",
    "age_list = [18,19,18,19,17,20,20,18,19,17,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "215454d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 17, 20]"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路1：remove(value),先决条件，知道值出现的次数\n",
    "删除的数量 = age_list.count(19) # age_list.count(19) 指19出现的次数\n",
    "for i in range(删除的数量):  # 要循环的次数为19出现的次数\n",
    "    if 19 in age_list:   # 如果19在 age_list 里，删除19\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "3e944071",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 19\n",
      "2 19\n",
      "6 19\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 17, 20]"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路2：pop(index)，先决条件，知道值出现的位置\n",
    "for i,v in enumerate(age_list):\n",
    "    if v == 19:\n",
    "        print(i,v)\n",
    "        age_list.pop(i)\n",
    "age_list "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ee2f63f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "## reserve，extend，clear，copy，sort"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0c69d94",
   "metadata": {},
   "source": [
    "#### reserve 将列表进行翻转"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ce25cdba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['cola', 'alex', 'marry']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "ae849fc1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['marry', 'alex', 'cola']\n"
     ]
    }
   ],
   "source": [
    "网三_name_list.reverse()\n",
    "print(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b47e8d2d",
   "metadata": {},
   "source": [
    "#### sort将列表进行排序  \n",
    "#### list = list.sort(cmp=Node, key=Node, reverse=False)  \n",
    "> cmp —> 可选参数，制定排序方案的函数  \n",
    "> key —> 参数比较  \n",
    "> reverse —> 排序规则，reverse = True (降序)；reverse = False (升序)，升序是默认状态  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a54b0b83",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = [\"dog\",\"cat\",\"pig\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e421f50a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['cat', 'dog', 'pig']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sort()\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1bd9bf9",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = [6,3,8,9,10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "91b3866a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 9, 8, 6, 3]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.sort(reverse = True ) # 降序排列\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "319dfb04",
   "metadata": {},
   "source": [
    "#### clear将当前的列表清空"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "77cd84b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "m = [6,3,8,9,10]\n",
    "print(len(m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "f43ffc04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "m.clear()\n",
    "print(len(m)) # 列表被清空，len变为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "699cad85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2250352",
   "metadata": {},
   "source": [
    "#### copy将当前列表复制一份新的列表，虽然新的列表虽与旧的列表的内容相同，但是内存地址不同"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "ecb30ea7",
   "metadata": {},
   "outputs": [],
   "source": [
    "old_list = [1, 2, 3, 4, 5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "950a124c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_list = old_list.copy()\n",
    "new_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "fe1fcdf0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1890697329280\n"
     ]
    }
   ],
   "source": [
    "print(id(old_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "af4c62a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1890697329856\n"
     ]
    }
   ],
   "source": [
    "print(id(new_list))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77254cfa",
   "metadata": {},
   "source": [
    "#### extend将其他列表或元组中的元素一次性的导入到当前列表中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "03457dbe",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = [\"xiaoli\",\"xiaoy\",\"xiaow\"]\n",
    "new_name = [\"xiaoh\",\"xiaoy\",\"xiaoz\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "b70b9c43",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['xiaoli', 'xiaoy', 'xiaow', 'xiaoh', 'xiaoy', 'xiaoz']\n"
     ]
    }
   ],
   "source": [
    "name.extend(new_name) # 将new_name导入到name中，且相同项不会被合并\n",
    "print(name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c37fa8ac",
   "metadata": {},
   "source": [
    "### 列表的方法（Function）--对列表数据进行操作--总结  \n",
    "> 增  \n",
    ">> append 增加，增加元素到末尾  \n",
    ">> insert 增加元素到某个位置  \n",
    "  \n",
    "> 删  \n",
    " >> remove 删除，有相同内容时，删除第一个  \n",
    ">> pop 默认删除最后一个元素,给值可删除指定元素  \n",
    ">> clear 将当前的列表清空  \n",
    "  \n",
    "> 其他\n",
    ">> reserve 将列表进行翻转  \n",
    ">> sort 将列表进行排序    \n",
    ">> copy 将当前列表复制一份新的列表，虽然新的列表虽与旧的列表的内容相同，但是内存地址不同  \n",
    ">> extend 将其他列表或元组中的元素一次性的导入到当前列表中"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67e17104",
   "metadata": {},
   "source": [
    "#### 书本P68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "585f087f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "## --\n",
    "for i in range(4):  ## 删除最后一个字符，并循环4次\n",
    "    plist.pop()\n",
    "    \n",
    "plist.pop(0)   ## 删除第一个字符\n",
    "plist.remove(\"'\")   ## 删除符号\n",
    "\n",
    "plist.extend([plist.pop(),plist.pop()])  ## 将最后两个字符踢出列表，再将其重组，并加入到原列表中，同时交换了p,a顺序\n",
    "plist.insert(2,plist.pop(3))  ## 将空格字符提出，并将其放到适当的位置\n",
    "## --\n",
    "\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "834bdf06",
   "metadata": {},
   "source": [
    "#### 书本P81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "77fe0756",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase+''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
